$(function () {
    $("#jqGrid").jqGrid({
        url: '../socialsecuritypersonbasic/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', key: true,hidden:true },
			{ label: '员工姓名', name: 'name', index: 'name' },
			{ label: '', name: 'empid', index: 'empid',hidden:true }, 			
			{ label: '结算点名称', name: 'settlementname', index: 'settlementname' },
			{ label: '', name: 'settlementid', index: 'settlementid',hidden:true }, 			
			{ label: '年', name: 'year', index: 'year' },
			{ label: '月', name: 'month', index: 'month' },
			{ label: '养老保险基数', name: 'yanglbxBasic', index: 'yanglbx_basic' }, 			
			{ label: '养老保险单位比例', name: 'yanglbxDwbl', index: 'yanglbx_dwbl' }, 			
			{ label: '养老保险个人比例', name: 'yanglbxGrbl', index: 'yanglbx_grbl' }, 			
			{ label: '医疗保险基数', name: 'yilbxBasic', index: 'yilbx_basic' }, 			
			{ label: '医疗保险单位比例', name: 'yilbxDwbl', index: 'yilbx_dwbl' }, 			
			{ label: '医疗保险个人比例', name: 'yilbxGrbl', index: 'yilbx_grbl' }, 			
			{ label: '失业保险基数', name: 'shiybxBasic', index: 'shiybx_basic' }, 			
			{ label: '失业保险单位比例', name: 'shiybxDwbl', index: 'shiybx_dwbl' }, 			
			{ label: '失业保险个人比例', name: 'shiybxGrbl', index: 'shiybx_grbl' }, 			
			{ label: '工伤保险基数', name: 'gongsbxBasic', index: 'gongsbx_basic' }, 			
			{ label: '工伤保险单位比例', name: 'gongsbxDwbl', index: 'gongsbx_dwbl' }, 			
			{ label: '工伤保险个人比例', name: 'gongsbxGrbl', index: 'gongsbx_grbl' }, 			
			{ label: '生育保险基数', name: 'shengybxBasic', index: 'shengybx_basic' }, 			
			{ label: '生育保险单位比例', name: 'shengybxDwbl', index: 'shengybx_dwbl' }, 			
			{ label: '生育保险个人比例', name: 'shengybxGrbl', index: 'shengybx_grbl' }, 			
			{ label: '公积金基数', name: 'gongjjBasic', index: 'gongjj_basic' }, 			
			{ label: '公积金单位比例', name: 'gongjjDwbl', index: 'gongjj_dwbl' }, 			
			{ label: '公积金个人比例', name: 'gongjjGrbl', index: 'gongjj_grbl' }, 			
			{ label: '大病基数', name: 'dabinBasic', index: 'dabin_basic' }, 			
			{ label: '大病单位比例', name: 'dabinDwbl', index: 'dabin_dwbl' }, 			
			{ label: '大病个人比例', name: 'dabinGrbl', index: 'dabin_grbl' }, 			
			{ label: '五险合一基数', name: 'totalBasic', index: 'total_basic' }, 			
			{ label: '五险合一单位比例', name: 'totalDwbl', index: 'total_dwbl' }, 			
			{ label: '五险合一个人比例', name: 'totalGrbl', index: 'total_grbl' }, 			
			{ label: '是否五险合一(0,不是，五险分开记录，1,是，使用五险合一。)', name: 'istotal', index: 'istotal' }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        //字段太多自动加载横轴滚动条
        shrinkToFit:false,
        autoScroll: false,
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	//$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		socialSecurityPersonBasic: {},
        q:{
            year:null,
            month:null
        }
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.socialSecurityPersonBasic = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.socialSecurityPersonBasic.id == null ? "../socialsecuritypersonbasic/save" : "../socialsecuritypersonbasic/update";
			$.ajax({
				type: "POST",
			    url: url,
			    contentType: "application/json",
			    data: JSON.stringify(vm.socialSecurityPersonBasic),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../socialsecuritypersonbasic/delete",
				    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get("../socialsecuritypersonbasic/info/"+id, function(r){
                vm.socialSecurityPersonBasic = r.socialSecurityPersonBasic;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
                postData:{
                    year: vm.q.year,
                    month:vm.q.month
                },
                page:page
            }).trigger("reloadGrid");
		}
	}
});